import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.SwingConstants;

public class VueSaisieLecteur extends Vue {

	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTextField textFieldNom;
	private JTextField textFieldPrenom;
	private JTextField textFieldAdresse;
	private JTextField textFieldTelephone;
	private JButton buttonEnreg;
	private JButton buttonAnnuler;
	
	/**
	 * Create the frame.
	 */
	public VueSaisieLecteur(Controleur controleur) {
		super(controleur);
		setTitle("Enregistrement d'un nouveau lecteur");
		//setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 
		setBounds(100, 100, 405, 293);
		contentPane = new JPanel();
		
		this.addWindowListener (new WindowAdapter() {
			public void windowClosing (WindowEvent e) {
			getControleur().fermerVue(VueSaisieLecteur.this);
			}
		});
		
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNom = new JLabel("Nom");
		lblNom.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNom.setBounds(83, 50, 61, 15);
		contentPane.add(lblNom);
		
		JLabel lblPrnom = new JLabel("Prénom");
		lblPrnom.setHorizontalAlignment(SwingConstants.RIGHT);
		lblPrnom.setBounds(83, 85, 61, 15);
		contentPane.add(lblPrnom);
		
		JLabel lblNewLabel = new JLabel("Adresse");
		lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel.setBounds(83, 122, 61, 15);
		contentPane.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("Téléphone");
		lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel_1.setBounds(66, 157, 78, 15);
		contentPane.add(lblNewLabel_1);
		
		textFieldNom = new JTextField();
		textFieldNom.setColumns(10);
		textFieldNom.setBounds(161, 48, 141, 19);
		contentPane.add(textFieldNom);
		
		textFieldPrenom = new JTextField();
		textFieldPrenom.setColumns(10);
		textFieldPrenom.setBounds(162, 83, 141, 19);
		contentPane.add(textFieldPrenom);
		
		textFieldAdresse = new JTextField();
		textFieldAdresse.setColumns(10);
		textFieldAdresse.setBounds(161, 120, 141, 19);
		contentPane.add(textFieldAdresse);
		
		textFieldTelephone = new JTextField();
		textFieldTelephone.setColumns(10);
		textFieldTelephone.setBounds(161, 155, 141, 19);
		contentPane.add(textFieldTelephone);
		
		buttonEnreg = new JButton("Enregistrer");
		buttonEnreg.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String nom = textFieldNom.getText();
				String prenom = textFieldPrenom.getText();
				String adresse = textFieldAdresse.getText();
				String telephone = textFieldTelephone.getText();
				getControleur().nouvLecteur(nom, prenom, adresse, telephone);
				}
		});		
		buttonEnreg.setBounds(274, 186, 107, 25);
		contentPane.add(buttonEnreg);
		
		buttonAnnuler = new JButton("Annuler");
		buttonAnnuler.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			getControleur().fermerVue(VueSaisieLecteur.this);}
		});		
		buttonAnnuler.setBounds(274, 223, 107, 25);
		contentPane.add(buttonAnnuler);
		
	}
	
	public void setEtat (int etat){
		switch (etat) {
		case initiale: {	
			buttonEnreg.setEnabled(true);
			buttonAnnuler.setEnabled(true);
			break;}
		}
		
	}
}
